//https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/description/
class Solution {
    public int[] searchRange(int[] nums, int target) {
        int left = 0;
        int right = nums.length-1;
        int midL = 0,midR = 0;
        //找左端点
        while (left < right) {
            midL = left+(right-left)/2;
            if (nums[midL] >= target) {
                right = midL;
            }else {
                left = midL+1;
            }
        }
        if (nums.length == 0 || nums[left] != target) return new int[]{-1,-1};
        midL = left;
        left = 0;
        right = nums.length-1;

        //找右端点
        while (left < right) {
            midR = left+(right-left+1)/2;
            if (nums[midR] <= target) {
                left = midR;
            }else {
                right = midR-1;
            }
        }
        midR = right;
        return new int[]{midL,midR};
    }
}


